/*
day226
2020.4.10
*/
#include<vector>
#include<cstdlib>
using namespace std;

struct TreeNode {
    int val;     
	TreeNode *left;
    TreeNode *right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};


class Solution {
public:
    TreeNode* buildTree(vector<int>& inorder, vector<int>& postorder) {
    	int cur=postorder.size()-1;
        return help(inorder,postorder,cur,0,postorder.size()-1);
    }
    
    TreeNode* help(vector<int>& inorder, vector<int>& postorder,int &cur,int l,int r)
    {
    	if(l>r)
    	{
    		return NULL;
		}
    	int cur_val=postorder[cur--];
    	
    	int i=l;
    	while(i<=r && inorder[i]!=cur_val) i++;
    	
    	TreeNode *root=new TreeNode(cur_val);
    	root->right=help(inorder,postorder,cur,i+1,r);
    	root->left=help(inorder,postorder,cur,l,i-1);
    	
    	return root;
	}
};


int main()
{
	return 0;
}
